﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace debugger
{
    public partial class Form5 : Form
    {
        public Form5()
        {
            InitializeComponent();
        }


        private void Form5_Load(object sender, EventArgs e)
        {
            trackBar1.Value = 20;
            trackBar2.Value = -10;
            trackBar3.Value = 20;
            trackBar4.Value = -10;
        }


        void f(int wid, int hei, double viswid, double vishei, double visx, double visy, int maxi, double maxm)
        {

            int i;
            int j;
            int index = 0;
            int clr;
            double ReaC;
            double ImaC;
            double dReaC;
            double dImaC;
            double ReaZ;
            double ImaZ;
            double ReaZ2;
            double ImaZ2;
            //int n;

            //n = 256 / maxi;

            dReaC = (viswid) / ((double)wid - 1);
            dImaC = (vishei) / ((double)hei - 1);

            Bitmap b = new Bitmap(wid, hei);
            ReaC = visy;
            for (j = 0; j < hei; j++)
            {
                ReaC += dReaC;
                ImaC = visx;
                for (i = 0; i < wid; i++)
                {
                    ImaC += dImaC;
                    ReaZ = 0;
                    ImaZ = 0;
                    ReaZ2 = 0;
                    ImaZ2 = 0;
                    clr = 1;

                    while (clr++ < maxi && ReaZ2 + ImaZ2 < maxm)
                    {
                        ReaZ2 = ReaZ * ReaZ;
                        ImaZ2 = ImaZ * ImaZ;
                        ImaZ = 2 * ImaZ * ReaZ + ImaC;
                        ReaZ = ReaZ2 - ImaZ2 + ReaC;
                    }

                    int v2 = clr & 0xFF;
                    b.SetPixel(i, j, Color.FromArgb(0, 0, v2));
                }

            }
            this.pictureBox1.Image = b;
        }

        void draw() {
            double viswid = trackBar3.Value / 10.0;
            double vishei = trackBar1.Value / 10.0;
            double visx = trackBar2.Value / 10.0;
            double visy = trackBar4.Value / 10.0;
            f(64, 48, viswid, vishei, visx, visy, 255, 4);
            this.Text = viswid + "," + vishei + "," + visx + "," + visy;
        }
        private void trackBar1_Scroll(object sender, EventArgs e)
        {
            draw();
        }

        private void trackBar2_Scroll(object sender, EventArgs e)
        {
            draw();
        }

        private void trackBar3_Scroll(object sender, EventArgs e)
        {
            draw();
        }

        private void trackBar4_Scroll(object sender, EventArgs e)
        {
            draw();
        }
    }
}
